﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MMDemo
{
    public partial class SortInputForm : Form
    {
        public SortInputForm()
        {
            InitializeComponent();
        }

        private int sort_num = 0;
        private string[] PxSortData;
        private void RamCrebtn_Click(object sender, EventArgs e)
        {
            InputStrtext.Text = "";
            Random ran = new Random();
            sort_num = ran.Next(5, 13);
            for (int i = 0; i < sort_num; ++i)
            {
                if (i != 0)
                {
                    InputStrtext.Text += ",";
                }
                InputStrtext.Text += ran.Next(10, 100);
            }
        }

        private void Okbtn_Click(object sender, EventArgs e)
        {
            String temp = InputStrtext.Text;
            PxSortData = temp.Split(',');
            try
            {
                if (PxSortData.Length >= 13 || PxSortData.Length < 5)
                {
                    MessageBox.Show("获得较佳的演示效果，请输入5-12个排序数据!");
                    return;
                }
               
                for (int i = 0; i < PxSortData.Length; ++i)
                {
                    if (Convert.ToUInt32(PxSortData[i]) > 99 || Convert.ToUInt32(PxSortData[i]) < 10)
                    {
                        MessageBox.Show("获得较佳的演示效果，数据大小为10-99!");
                        return;
                    }
                }
            }
            catch
            {
                MessageBox.Show("输入排序数值不符合规定!");
                return;
            }        
            GlobalSort.SortData = temp;
            PublicDataClass.IsInit = true;
            this.Close();
        }

        protected override void WndProc(ref   Message m)
        {
            const int WM_SYSCOMMAND = 0x0112;
            const int SC_CLOSE = 0xF060;
            if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
            {
                PublicDataClass.IsInit = false;
                this.Close();
                return;
            }
            base.WndProc(ref m);
        }
    }
}
